<?php
/**
 * @copyright Copyright (c) 2021 勾股工作室
 * @license https://opensource.org/licenses/GPL-3.0
 * @link https://www.gougucms.com
 */

namespace app\bitjob\model;

use think\facade\Db;
use think\Model;

class BitjobPutpay extends Model
{
    const ZERO = 0;
    const ONE = 1;
    const TWO = 2;
    const THREE = 3;
    const FORE = 4;
    const FIVE = 5;
    const SIX = 6;

    public static $Status = [
        self::ZERO => '待上报',
        self::ONE => '审核中',
        self::TWO => '审核通过',
        self::THREE => '审核拒绝',
        self::FORE => '已撤销',
        self::FIVE => '已中止',
        self::SIX => '已作废',
    ];

    //列表检索
    public function get_list($param = [], $where = [], $whereOr=[])
    {

        $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
        $list = self::where($where)
            ->where(function ($query) use($whereOr) {
                $query->whereOr($whereOr);
            })
            ->field('a.*')
            ->alias('a')
            ->order('a.create_time desc')
            ->paginate($rows, false, ['query' => $param])
            ->each(function ($item, $key) {
                $item->status_name = self::$Status[(int)$item->status];
            });
        return $list;
    }


    // 获取合同详情
    public function detail($id)
    {
        $detail = self::where(['id' => $id])->find();
        if (!empty($detail)) {
            $detail['create_user'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name');
            $detail['status_name'] = self::$Status[(int) $detail['check_status']];
            if($detail['file_ids'] !=''){
                $fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
                $detail['fileArray'] = $fileArray;
            }
        }
        return $detail;
    }
}
